<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal">
                    <input type="hidden" readonly id="receiveMember" name="receiveMember" class="form-control" value="${user.userRealname}">
                    <div class="form-group">
                        <label class="control-label col-sm-1">PO:</label>
                        <div class="col-sm-2">
                            <input type="text" id="receiveNo" name="receiveNo" class="form-control">
                        </div>

                        <label class="control-label col-sm-1">SKU:</label>
                        <div class="col-sm-2">
                            <input type="text" id="receiveSku" name="receiveSku" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">渠道:</label>
                        <div class="col-sm-2">
                            <select  name="receiveChannelName" id="receiveChannelName" class="form-control">
                                <option value="">请选择渠道</option>
                                <%for(var dict in channel){%>
                                <option value="${dict.channelName}"  >${dict.channelName}</option>
                                <%}%>
                            </select>
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-1">商品名称:</label>
                        <div class="col-sm-2">
                            <input type="text" id="productName" name="productName" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">供应商:</label>
                        <div class="col-sm-2">
                            <input type="text" id="produceSupplierName" name="produceSupplierName" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">颜色:</label>
                        <div class="col-sm-2">
                            <input type="text" id="productColorName" name="productColorName" class="form-control">
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
            <!-- START 操作按钮 -->

            <!-- END 操作按钮 -->
            <form>
                <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                    <button  class="layui-btn layui-btn-sm import-btn"   id="import-btn"  name="import-btn" style="margin-top: -6px;margin-left: -4px">
                        <i class="layui-icon"></i>直发国内仓
                    </button>
                    <button  class="layui-btn  layui-btn-sm layui-btn-danger" style="margin-top: -6px;margin-left: -4px">
                        <i class="fa fa-download"></i>
                        <a href="/excel/直发国内仓模板.xlsx" style="color: white" download>直发模板下载</a>
                    </button>
                    <button  class="layui-btn layui-btn-sm import-btn layui-btn-warm order-date-btn" name="order-date-btn" style="margin-top: -6px;margin-left: -4px">
                        <i class="fa fa-link" aria-hidden="true"></i>修改交期
                    </button>

                    <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                        <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                    </button>
                </div>
            </form>
            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/supply/receive/findByShipped.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>


<div id="layer_buy_date_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-date-form" method="post" autocomplete="off" style="margin: auto">

            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">预计交期</label>
                <div class="col-sm-6" style="max-width: 300px;max-height: 300px;">
                    <input type="text" id="buyDate" name="buyDate" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-date-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,bootstrap-table-zh-CN,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,layui,chosen,chosen-demo,upload'}){}%>
<script>

    laydate.render({
        elem: '#buyDate' //指定元素
        ,trigger: 'click'
    });

    var $relatedTable = $('#relatedTable');
    $(function(){
        //START 表格配置
        $relatedTable.bootstrapTable({

            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '付款方式',
                    field: 'paymentType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'PO',
                    field: 'receiveNo',
                    align: 'center',
                    valign: 'middle'
                },

                {
                    title: '渠道',
                    field: 'receiveChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'SKU',
                    field: 'receiveSku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '供应商',
                    field: 'produceSupplierName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'productName',
                    title: '产品名称',
                    align: 'center'
                },
                {
                    field: 'productColorName',
                    title: '产品颜色',
                    align: 'center'
                },
                {
                    field: 'productCm',
                    title: '尺码(CM)',
                    align: 'center'
                },
                {
                    field: 'productInch',
                    title: '尺码(INCH)',
                    align: 'center'
                },
                {
                    field: 'orderDate',
                    title: '预计交期',
                    align: 'center'
                },
                {
                    field: 'producePrice',
                    title: '含税价',
                    align: 'center'
                },
                {
                    field: 'produceUnitPrice',
                    title: '不含税价',
                    align: 'center'
                },
                {
                    field: '',
                    title: '总价',
                    align: 'center',
                    formatter:function(v,r){
                        return ((r.receiveNumber-r.produceShort)*r.producePrice).toFixed(2);
                    }
                },
                {
                    title: '待接收数量',
                    field: '',
                    align: 'center',
                    valign: 'middle',
                    formatter:function(v,r){
                        return (r.receiveNumber-r.produceShort);
                    }
                },
                {
                    title: '占有量',
                    field: 'produceUse',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '预占有量',
                    field: 'produceReadyUse',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '占有柜号',
                    field: 'receivePlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '合同号',
                    field: 'produceAgreement',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '装箱量',
                    field: 'productPackageNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '箱数',
                    field: 'boxNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                //删除
                $('.del-btn').on('click',function(){
                    var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-name');
                    layer.confirm('确定要关闭当前采购单？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        var index = layer.load();
                        $.post('/sea/supply/produceDetail/updateFlag.do',{flag:1,id: delid},function(data){
                            if( data.ok ){
                                layer.close(index);
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $relatedTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                                layer.close(index);
                            }
                        });
                    });
                });
            }
        });

        $('.search-btn').on('click',function(){
            $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/receive/findByShipped.do?'+$('#search-form').serialize() });
        });
    });
    $(".export-btn").click(function () {
        window.location.href='/sea/supply/receive/exportShipped.do?'+$('#search-form').serialize();
    });



    function optFormatter(value,row){
        var content = '';
        if(row.flag==0){
            content += '&nbsp;<button class="del-btn btn btn-xs btn-danger" data-val="'+row.id+'" title="删除"><i class="fa fa-trash-o"></i> 关闭订单</button>';
        }
        console.log(row.flag);
        return content;
    }

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn', //绑定元素,
            accept:'file',
            url: '/sea/supply/ware/produce/import/', //上传接口
            data:{"receiveMember":$("#receiveMember").val()},
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $relatedTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    $('.order-date-btn').on('click',function () {
        layer.open({
            type:1,
            title:'修改交期',
            area:['450px','270px'],
            skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
            shadeClose:false,
            resize: false,
            scrollbar: false,
            maxmin: false,//出现最大化按钮
            content:$('#layer_buy_date_window')
        })
    });

    $('.save-date-btn').on('click',function () {
        var buyDate=$("#buyDate").val();
        if(buyDate==''){
            parent.layer.msg('请选择交期！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }
        var selDatas = $relatedTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            var ids = [];
            $.each(selDatas,function(i,d){
                ids.push(d.buyId);
            });
            ids = ids.join(',');
            $.ajax({
                url: "/sea/supply/buy/updateOderDate",
                data: {
                    buyIds:ids,
                    buyDate:buyDate
                },
                type: "post",
                success: function (data) {

                    if(data.ok){
                        layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                layer.closeAll();
                                $relatedTable.bootstrapTable('refresh');
                            }});
                    }else{
                        layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                layer.closeAll();
                            }});
                    }
                },
            });
        }
    });
</script>
</body>
</html>
